package com.cms.service;

import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.cms.domain.Config;
import com.cms.domain.TableField;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 获取系统设置 服务实现类
 * </p>
 *
 * @author songfayuan
 * @since 2021-11-12
 */
@Service
public class ConfigService {

    @Autowired
    private SetupService setupService;

    /**
     * 获取系统设置
     *
     * @return 系统设置
     */
    @Cacheable(cacheNames = "config")
    public Config getConfig() {
        Map<String,String> setupMap = setupService.getSetupMap();
        Config config = new Config();
        for(String key : setupMap.keySet()){
            try {
                BeanUtils.setProperty(config, key, setupMap.get(key));
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return config;
    }



}
